package com.egao.common.manage.college;

import cn.hutool.core.util.StrUtil;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.exception.BusinessException;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.dispatch.entity.Dispatch;
import com.egao.common.module.dispatch.service.DispatchService;
import com.egao.common.module.system.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 派遣信息(学院)
 * @author pyx
 * @Date 2021/6/25
 */
@Api(tags = "学院派遣信息")
@RestController
@RequestMapping("${api}")
public class CollegeDispatchController extends BaseController {
    @Autowired
    private DispatchService dispatchService;

    @PreAuthorize("hasAuthority('college:dispatch:list')")
    @ApiOperation("分页查询派遣信息")
    @OperLog(value = "分页查询派遣信息", desc = "学院")
    @GetMapping("/college/dispatch/page")
    public PageResult<Dispatch> page(HttpServletRequest request) {
        User loginUser = getLoginUser();

        if (StrUtil.isBlank(loginUser.getCollegeCode())) {
            throw new BusinessException("没有找到您的学院信息，请联系就业中心");
        }

        PageParam<Dispatch> pageParam = new PageParam<>(request);
        pageParam.put("collegeCode",loginUser.getCollegeCode());
        pageParam.setDefaultOrder(null, new String[]{"create_time"});
        return new PageResult<>(dispatchService.listPage(pageParam),pageParam.getTotal());
    }

}
